<template>
  <div class="anchorstation">
    <p class="title">主播电台</p>
    <div class="djRadios" v-for="item in djRadios" :key="item.id" @click="toDjDetail(item.id)">
      <div class="left">
        <img :src="item.picUrl" />
        <span class="name">{{ item.name }}</span>
      </div>
      <div class="nickname">
        <span>by </span>
        <span>{{item.dj.nickname }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { getCloudSearch } from '../../network/search.js'
export default {
  props: ['type', 'value'],
  data () {
    return {
      djRadios: [],
      djRadiosCount: 0
    }
  },
  methods: {
    toDjDetail (id) {
      this.$router.push('/program_detail/' + id)
    },
    getCloudSearch (type, keywords) {
      getCloudSearch(type, keywords).then(res => {
        // console.log(res.data)
        this.djRadios = res.data.result.djRadios
        this.djRadiosCount = res.data.result.djRadiosCount
        this.$emit('singerCount', this.djRadiosCount + ' 个电台')
        // console.log(this.djRadios)
      })
    }
  },
  created () {
    this.getCloudSearch(this.type, this.value)
  },
  watch: {
    value (newVal, oldVal) {
      // console.log('新关键词:' + newVal)
      this.value = newVal
      this.getCloudSearch(this.type, this.value)
    }
  }
}
</script>

<style lang="less" scoped>
  .djRadios {
    width: 100%;
    padding: 15px;
    display: flex;
    flex-direction: row;
    align-items: center;
    .left {
      display: flex;
      flex-direction: row;
      align-items: center;
      width: 50%;
      img {
        width: 75px;
        height: 75px;
        border-radius: 5px;
        margin-right: 15px;
      }
      .name {
        font-size: 15px;
      }
    }
    .nickname {
      color: #c8c8c8;
      span:last-child {
        color: #9c9c9c;
      }
    }
  }
  .djRadios:nth-child(2n) {
    background-color: #f9f9f9;
  }
  .djRadios:hover {
    background-color: #f0f1f2;
  }
  .title {
    color: #b3b3b3;
    padding: 0 10px 10px;
  }
</style>
